import 'package:boss/models/delivery_setting_data.dart';
import 'package:boss/ui/page/takeoutManagement/page/widget/double_formfield.dart';

import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class DeliveryRuleRow extends StatelessWidget {
  final TakeoutCostSettingFormList data;
  final ValueChanged<String> onKmChanged;
  final ValueChanged<String> onPriceChanged;
  final VoidCallback onDelete;
  final bool enabled;

  const DeliveryRuleRow({
    Key key,
    @required this.data,
    this.onKmChanged,
    this.onPriceChanged,
    this.onDelete,
    this.enabled,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DoubleFormField(
      firstText: '门店范围',
      secondText: '公里内，',
      thirdText: '配送金额',
      fourthText: '元',
      firstInputType: TextInputType.numberWithOptions(decimal: true),
      firstInputFormatters: [
        FilteringTextInputFormatter.allow(RegUtil.integerReg),
      ],
      secondInputType: TextInputType.numberWithOptions(decimal: true),
      secondInputFormatters: [
        FilteringTextInputFormatter.allow(RegUtil.numberReg),
      ],
      firstInitValue: data?.targetValue?.toString(),
      secondInitValue: AmountUtil.price2String(data.costAmount),
      onFirstChanged: onKmChanged,
      onSecondChanged: onPriceChanged,
      onDelete: onDelete,
      firstMaxLength: 6,
      secondMaxLength: 6,
      enabled: enabled,
    );
  }
}
